package com.hibernate.table;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class QueryCustomer {

	private static SessionFactory factory = new Configuration().configure().buildSessionFactory();
	private static Session session;

	public static void main(String[] args) {
		//GetCustomer(6);
		//QueryCustomer();
		SaveCustomer();
	}

	public static void GetCustomer(int id) {
		session = factory.openSession();
		Customer c = (Customer) session.get(Customer.class, id);
		System.out.println("Customer:Id=" + c.getId() + ", Name=" + c.getName() + ", Address=" + c.getAddress());
		session.close();
	}

	public static void SaveCustomer() {
		session = factory.openSession();
		Customer c = new Customer();
		c.setAddress("Phakanong");
		c.setId(14);
		c.setName("North");
		session.beginTransaction();
		session.save(c);
		session.getTransaction().commit();
		session.close();
	}

	public static void QueryCustomer() {

	}

}
